<?php

namespace wxml\libs;

use Yii;
use wxml\models\user\User;
use yii\base\Model;

class CommonUserModel{


    private $retCode=0;
    private $retMessage="";
    public $access_token;
    public $user_id;

    function __construct(array $config) {
        $this->formateParams();
        $this->checkAccessToken();
    }

    private function formateParams(){
        $user_id=Yii::$app->request->post("user_id");
        $access_token=Yii::$app->request->post("access_token");
        if(empty($user_id)||empty($access_token)) {
            $this->retCode=-1;
            $this->retMessage="缺少必要参数";
            return false;
        }else{
            $this->user_id=$user_id;
            $this->access_token=$access_token;
        }
    }

    private function checkAccessToken() {

            $user = new User();
            if(!$user->checkAccessToken($this->user_id, $this->access_token)) {
                $this->retCode=$user->getStatus();
                $this->retMessage=$user->getErrMsg();
            }
    }

    public function getResult(){
        return [
            'status'=>$this->retCode,
            'msg'=>$this->retMessage
        ];
    }

    public function setResult($status,$message){
        $this->retCode=$status;
        $this->retMessage=$message;
    }

}
